package com.hp.gxw.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;

@Slf4j
public class Base64Util {

    public static String ioToBase64(InputStream in) throws Exception {
        byte[] strBase64 = null;
        try {
            byte[] bytes = new byte[in.available()];
            // 将文件中的内容读入到数组中
            in.read(bytes);
            strBase64 = Base64.getEncoder().encode(bytes);      //将字节流数组转换为字符串
            in.close();
        } catch (IOException ioe) {
            log.error("图片转64编码异常",ioe);
        }
        return new String(strBase64, "UTF-8");
    }
}